package main

import (
	"fmt"
	"sync"
	"time"
)

/*
类似于java中的CountDownLatch

sync.WaitGroup

Add(n)规定需要有n个线程调用了Done才可以通过
Done()类似于latch.countDown()
Wait()类似于latch.await()
*/

var wg sync.WaitGroup

func testing() {
	fmt.Println("调用了testing")
	time.Sleep(2 * time.Second)
	wg.Done()
}
func main() {
	wg.Add(2)
	go testing()
	go testing()
	wg.Wait()
	fmt.Println("主线程结束")
}
